# coding=utf-8
# !/usr/bin/python3
# @Time:2021/2/24 8:17 上午
# @Author:wangyun
# @File:SendSMS.py

from ronglian_sms_sdk import SmsSDK
import json
accId = '8aaf070877bee8430177cdf3c0c20539'
accToken = '90a637b2da3e4a04afdbdd8ed8663a2b'
appId = '8aaf070877bee8430177cdf3c1c5053f'


class CPP(object):
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, '_instance'):
            cls._instance = super(CPP, cls).__new__(cls, *args, **kwargs)
            cls._instance.sdk = SmsSDK(accId, accToken, appId)
        return cls._instance

    def send_message(self, mobile, datas, tid):

        # tid = '容联云通讯创建的模板'
        # mobile = '15110159583'
        # datas = ('变量1', '变量2')
        #发短信有延迟
        resp = self.sdk.sendMessage(tid, mobile, datas)
        json_resp = json
        print(resp)
        statusCode = json_resp.get('statusCode')
        if statusCode == '000000':
            return 0
        else:
            return -1


if __name__ == '__main__':
    # send_message()
    CPP().send_message(mobile='15110159583', datas=['123456', 5], tid=1)
